<?php

namespace App\Console\Commands;

use App\Library\Logic\AuctionLogic;
use Exception;
use Illuminate\Console\Command;

class AuctionStartCommand extends Command
{
    /**
     * 拍卖开始更改开始参数状态
     *
     * @var string
     */
    //protected $signature = 'command:auctionStart {serialNumber}';
    protected $signature = 'command:auctionStart';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     * @throws Exception
     */
    public function handle(): void
    {
        $list = AuctionLogic::query()->where(humpToLine([
            'status' => 1,
            'auditStatus' => 1,
            'isStart' => 0,
            ['start_at', '<=', now()],
        ]))->get();
        if (is_null($list)) return;
        foreach ($list as $auction) {
            $auction->is_start = 1;
            $auction->current_price = $auction->start_price;
            $auction->save();
            mq('auctionEnd', $auction->serial_number, $auction->end_at);
        }
    }

    /**
     * Execute the console command.
     * @throws Exception
     */
    /*public function handle(): void
    {
        $serialNumber = $this->argument('serialNumber');;
        if (empty($serialNumber) || strlen($serialNumber) !== 20) return;
        else if (AuctionLogic::query()->where(humpToLine([
            'status' => 1,
            'auditStatus' => 1,
            'isStart' => 0,
            ['start_at', '<=', now()],
            'serialNumber' => $serialNumber,
        ]))->update(humpToLine(['isStart' => 1]))) {
            $auction = AuctionLogic::findBySerialNumber($serialNumber);
            if (is_null($auction)) return;
            $auction->current_price = $auction->start_price;
            $auction->save();
            mq('auctionEnd', $auction->serial_number, $auction->end_at);
        }
    }*/
}
